<?php

namespace app\index\model;

use think\Model;

class Star extends BaseModel
{

    public static function getByOnline()
    {
        return self::where('onlineswitch', 1)->order(['year asc', 'quarterdata asc', 'weigh desc'])->select();
    }

    public static function getYear($stars)
    {
        return array_values(array_unique(array_column($stars, 'year')));
    }

    public static function getAll($stars)
    {
        $year = array_values(array_unique(array_column($stars, 'year')));
        $quarter = array_values(array_unique(array_column($stars, 'quarterdata')));
        $data = [];
        foreach ($year as $y) {
            foreach ($quarter as $q) {
                foreach ($stars as $val) {
                    if ($val['year'] == $y) {
                        if ($val['quarterdata'] == $q) {
                            $data[$y][$q][] = $val;
                        }
                    }
                }
            }
        }
        return $data;
    }

}
